package com.atguigu.daijia.order.service.impl;

import com.atguigu.daijia.model.entity.order.OrderMonitor;
import com.atguigu.daijia.model.entity.order.OrderMonitorRecord;
import com.atguigu.daijia.order.mapper.OrderMonitorMapper;
import com.atguigu.daijia.order.repository.OrderMonitorRecordRepository;
import com.atguigu.daijia.order.service.OrderMonitorService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class OrderMonitorServiceImpl extends ServiceImpl<OrderMonitorMapper, OrderMonitor> implements OrderMonitorService {

    @Autowired
    private OrderMonitorRecordRepository orderMonitorRecordRepository;

    //保存订单监控记录数据到mongodb中
    @Override
    public Boolean saveOrderMonitorRecord(OrderMonitorRecord orderMonitorRecord) {
        //保存至Mongodb中
        orderMonitorRecordRepository.save(orderMonitorRecord);
        return true;
    }

    //保存订单监控记录到mysql中
    @Override
    public Long saveOrderMonitor(OrderMonitor orderMonitor) {
        boolean isSuccess = this.save(orderMonitor);
        return orderMonitor.getId();
    }

    //根据订单id查询监控记录
    @Override
    public OrderMonitor getOrderMonitor(Long orderId) {
        LambdaQueryWrapper<OrderMonitor> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OrderMonitor::getOrderId,orderId);
        OrderMonitor orderMonitor = this.getOne(queryWrapper);
        return orderMonitor;
    }

    //修改订单记录
    @Override
    public Boolean updateOrderMonitor(OrderMonitor orderMonitor) {
        boolean isSuccess = this.updateById(orderMonitor);
        return isSuccess;
    }
}
